package com.doit.day01;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.Cell;
import org.apache.hadoop.hbase.CellUtil;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.client.*;

import java.nio.charset.StandardCharsets;
import java.util.ArrayList;

public class _02_get数据 {
    public static void main(String[] args) throws Exception {
        Configuration conf = HBaseConfiguration.create();
        conf.set("hbase.zookeeper.quorum","linux01:2181");

        Connection conn = ConnectionFactory.createConnection(conf);

        Table table = conn.getTable(TableName.valueOf("doit:abc"));

//        Get get = new Get("rowkey001".getBytes(StandardCharsets.UTF_8));
        Get get1 = new Get("rowkey002".getBytes(StandardCharsets.UTF_8));
        Get get2 = new Get("rowkey003".getBytes(StandardCharsets.UTF_8));
//        get.addColumn("f2".getBytes(StandardCharsets.UTF_8),"name".getBytes(StandardCharsets.UTF_8));
//        get.addFamily("f3".getBytes(StandardCharsets.UTF_8));

        ArrayList<Get> gets = new ArrayList<>();
//        gets.add(get);
        gets.add(get2);
        gets.add(get1);

        Result[] results = table.get(gets);
        for (Result result : results) {
            while (result.advance()){
                Cell current = result.current();
                String family = new String(CellUtil.cloneFamily(current));
                String qualifier = new String(CellUtil.cloneQualifier(current));
                String value = new String(CellUtil.cloneValue(current));
                String rowKey = new String(CellUtil.cloneRow(current));
                System.out.println(rowKey+"=>"+family+"=>"+qualifier+"=>"+value);
            }
        }




    }
}
